package LeetCode_Section;//相交链表
//https://leetcode.cn/problems/intersection-of-two-linked-lists/description/

//总有一天我们会在相交的地点相遇

public class CrosspointLinked {
      public class ListNode {
      int val;
      ListNode next;
      ListNode(int x) {
          val = x;
          next = null;
      }
  }

    public class Solution {
        public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
            ListNode curA = headA;
            ListNode curB = headB;
            if (headA == null || headB == null) {
                return null;
            }


            while (curA != curB) {
                curA = curA != null ? curA = curA.next : headB;
                curB = curB != null ? curB = curB.next : headA;
            }

            return curA;

        }
    }


}
